<template>
  <div>
    <dami-dialog @confirm="confirm" @cancel="cancel">
      <el-form :inline="false" class="demo-form-inline">
        <el-form-item label="商铺名字">
          <el-input v-model="options.Name" placeholder="商铺名字"></el-input>
        </el-form-item>
        <el-form-item label="手机号">
          <el-input v-model="options.Tel" placeholder="手机号"></el-input>
        </el-form-item>
        <el-form-item label="网址">
          <el-input v-model="options.Website" placeholder="网址"></el-input>
        </el-form-item>
        <el-form-item label="公众号">
          <el-input v-model="options.PublicNum" placeholder="公众号"></el-input>
        </el-form-item>
        <el-form-item label="公司地址">
          <el-input v-model="options.Address" placeholder="公司地址"></el-input>
        </el-form-item>
        <el-form-item label="业务咨询电话">
          <el-input v-model="options.LinkTel" placeholder="业务咨询电话"></el-input>
        </el-form-item>
        <el-form-item label="商城图标">
          <upload ref='upload' :action-url='imgUploadPath' :multiple='false'></upload>
        </el-form-item>


      </el-form>
    </dami-dialog>

  </div>
</template>

<script type="text/javascript">
import SYS_Store_update from  '../../../API/SYS_Store_update.js';
import upload from  '../../../component/upload';

const config = require('../../../../config');
const imgUploadPath = !!process.env  ? config.dev.imgUploadPath : config.build.imgUploadPath;
const imgPath = !!process.env  ? config.dev.imgPath : config.build.imgPath;

  export default {
    data(){
      return {
        imgUploadPath:imgUploadPath,
        options:{
          Name:'',//商铺名字
          Tel:'',//手机号
          Website:'',//网址
          PublicNum:'',//公众号
          Address:'',//公司地址
          LinkTel:'',//业务咨询电话
          Avatar:''
        }
      }
    },
    props:['storedata','viewState'],
    watch:{
      viewState(val){
        if(!!val){
          this.initData();
        }
      }
    },
    mounted:function(){
      this.initData();
    },
    components:{
      'upload':upload
    },
    methods:{
      initData(){
        this.options.Name = this.storedata.Name;
        this.options.Tel = this.storedata.Tel;
        this.options.Website = this.storedata.Website;
        this.options.PublicNum = this.storedata.PublicNum;
        this.options.Address = this.storedata.Address;
        this.options.LinkTel = this.storedata.LinkTel;
        this.options.Avatar = this.storedata.Avatar;
        if(!!this.options.Avatar){
          this.$refs.upload.initData([imgPath+this.options.Avatar])
        }
      },
      confirm(){
        this.$refs.upload.upload(data => {



          if(data.res == "1"){
            let imgList = data.imgList[0];
            this.options.Avatar = imgList.value;
          }else{
            this.options.Avatar = "";
          }



          SYS_Store_update(this.options).then(data => {
            this.$Message({
                message:"操作成功"
            });
            this.$emit("confirm");
            this.$refs.upload.reset();
          }).catch(message => {
            this.$Message({
                message
            });
          });


        });


      },
      cancel(){
        this.$emit("cancel");
        this.$refs.upload.reset();
      }
    }
  }
</script>
